﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using BookStore.Models;
namespace BookStore
{
    [HandleError]
    public class Utils
    {
        public Utils() {}
        public static string GetMD5Hash(string input)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }

        public static int Now()
        {
            DateTime d_now = DateTime.Now;
            DateTime d_old = new DateTime(1970, 1, 1);
            return (int)((d_now.Ticks - d_old.Ticks) / 10000000);
        }
        public static int DateToInt(string date)
        {
            string[] _date = date.Split(Convert.ToChar("-"));
            DateTime d_now = new DateTime(Convert.ToInt32(_date[2]), Convert.ToInt32(_date[1]),Convert.ToInt32( _date[0]));
            DateTime d_old = new DateTime(1970, 1, 1);
            return (int)((d_now.Ticks - d_old.Ticks) / 10000000);
        }
        public static bool IsNumber(string pValue)
        {
            foreach (Char c in pValue)
            {
                if (!Char.IsDigit(c))
                    return false;
            }
            return true;
        }
    }
}
